package com.wandian.audio.mvvm.audiosingersong;

import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.audio.R;
import com.wandian.audio.adapter.AudioSingerSongRecycleAdapter;
import com.wandian.audio.bean.SingerSongEntityBean;
import com.wandian.audio.databinding.AudioActivitySingerSongBinding;
import com.wandian.audio.tools.MusicCollector;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 歌手所有音乐activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_AUDIO_SINGER_SONG)
public class AudioSingerSongActivity extends BaseMVVMActivity<AudioSingerSongViewModel> {
    private AudioActivitySingerSongBinding dataBinding;
    private AudioSingerSongRecycleAdapter audioSingerSongRecycleAdapter;
    private int pageSize =50;
    private int pageNumber =0;
    private String music_id="";
    private String music_author="";
    private String music_singer_head ="";
    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.audio_activity_singer_song);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        Bundle bundle = getIntent().getExtras();
        if(bundle != null){
            music_id = bundle.getString("music_id");
            music_author = bundle.getString("music_author");
            music_singer_head = bundle.getString("music_singer_head");
        }
        initRecycle();
        initViewData();
        initClink();
        mViewModel.getMusicSingerSong(music_id,pageSize,pageNumber,System.currentTimeMillis()+"");
    }

    private void initRecycle(){
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
        dataBinding.recycler.setLayoutManager(layoutManager);
        audioSingerSongRecycleAdapter  = new AudioSingerSongRecycleAdapter(R.layout.audio_item_singer_song_list_view,music_author+"",music_singer_head);
        dataBinding.recycler.setAdapter(audioSingerSongRecycleAdapter);
        audioSingerSongRecycleAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                SingerSongEntityBean musicBean = (SingerSongEntityBean) baseQuickAdapter.getData().get(i);
                if(!UIUtils.isEmpty(musicBean)){
                    Bundle bundle = new Bundle();
                    bundle.putString("music_type","network");
                    bundle.putString("music_id",musicBean.getId()+"");
                    ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_AUDIO_MAIN).with(bundle).navigation();
                }
            }
        });
    }

    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText(music_author+"专辑");
        mViewModel.listData.observe(this,listBean->{
            if(!UIUtils.isEmpty(listBean)){
                MusicCollector.clearAllSong();
                MusicCollector.setToSongsList(mViewModel.listData.getValue(),music_author+"");
                audioSingerSongRecycleAdapter.setNewData(listBean);
            }
        });
    }

    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> {
            finish();
        });
    }



}
